/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package testgui;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

/**
 *
 * @author Administrator
 */
public class Player {
    
    private int xPos = 0;
    private int yPos = 0;
    private int[] intArraySizeOfHexGrid = new int[2];
    private int[][] intArrayHexGrid = new int[intArraySizeOfHexGrid[0]]
                                             [intArraySizeOfHexGrid[1]];
    private int[] currentPosition = new int[2];
    private JLabel jLabelConntectedToPlayer;
    
    public Player()
    {
        
    }
    
    public Player(int[] intArrayStartingPos, int numberOfRows, 
            int numberOfColumns, int startPosHoz, int startPosVert, JLabel jLabel)
    {
        xPos = intArrayStartingPos[0];
        yPos = intArrayStartingPos[1];
        
        intArraySizeOfHexGrid[0] = numberOfRows;
        intArraySizeOfHexGrid[1] = numberOfColumns;
        
        currentPosition[0] = startPosHoz;
        currentPosition[1] = startPosVert;
        
        jLabelConntectedToPlayer = jLabel;
        
        //System.out.println(jLabelConntectedToPlayer);
        
    }
    
    public JLabel getJLabel()
    {
        return jLabelConntectedToPlayer;
    }
            
    
    private boolean isCurrentRowEven()
    {
        return currentPosition[0] % 2 == 0;
    }
    
    private boolean isCurrentColumnEven()
    {
        return currentPosition[1] % 2 == 0;
    }
    
    private void playerUpdatePosNorthWest()
    {
        updatePlayerPos(getXPos() - 16, getYPos() - 27);
        
        if(isCurrentRowEven() && isCurrentColumnEven())
        {
            //System.out.println("even, even");
            updatePlayerPosInGrid(-1, -1);
        }
        
        else if(!isCurrentRowEven() && isCurrentColumnEven())
        {
        //System.out.println("odd, even");
        updatePlayerPosInGrid(-1, -1);
        }
        
        else if(isCurrentRowEven() && !isCurrentColumnEven())
        {
        //System.out.println("even, odd");
        updatePlayerPosInGrid(0, -1);
        }
        
        else
        {
        //System.out.println("odd, odd");
        updatePlayerPosInGrid(0, -1);
        }
        
       
    }
    
    private void playerUpdatePosNorth()
    {

    }
    
    private void playerUpdatePosNorthEast()
    {
       updatePlayerPos(getXPos() + 16, getYPos() - 27);
       
        if(isCurrentRowEven() && isCurrentColumnEven())
        {
            //System.out.println("even, even");
            updatePlayerPosInGrid(0, -1);
        }
        
        else if(!isCurrentRowEven() && isCurrentColumnEven())
        {
        //System.out.println("odd, even");
        updatePlayerPosInGrid(0, -1);
        }
        
        else if(isCurrentRowEven() && !isCurrentColumnEven())
        {
        //System.out.println("even, odd");
        updatePlayerPosInGrid(+1, -1);
        }
        
        else
        {
        //System.out.println("odd, odd");
        updatePlayerPosInGrid(+1, -1);
        }
        

    }
    
    private void playerUpdatePosWest()
    {
       updatePlayerPos(getXPos() - 32, getYPos());
       updatePlayerPosInGrid(-1, 0);
    }
    
    private void playerUpdatePosEast()
    {
       updatePlayerPos(getXPos() + 32, getYPos());
       updatePlayerPosInGrid(+1, 0);
    }
    
    private void playerUpdatePosSouthWest()
    {
       updatePlayerPos(getXPos() - 16, getYPos() + 27);
       
       if(isCurrentRowEven() && isCurrentColumnEven())
        {
            //System.out.println("even, even");
            updatePlayerPosInGrid(-1, +1);
        }
        
        else if(!isCurrentRowEven() && isCurrentColumnEven())
        {
        //System.out.println("odd, even");
        updatePlayerPosInGrid(-1, +1);
        }
        
        else if(isCurrentRowEven() && !isCurrentColumnEven())
        {
        //System.out.println("even, odd");
        updatePlayerPosInGrid(0, +1);
        }
        
        else
        {
        //System.out.println("odd, odd");
        updatePlayerPosInGrid(0, +1);
        }
    }
    
    private void playerUpdatePosSouth()
    {

    }
    
    private void playerUpdatePosSouthEast()
    {
       updatePlayerPos(getXPos() + 16, getYPos() + 27);
       
       if(isCurrentRowEven() && isCurrentColumnEven())
        {
            //System.out.println("even, even");
            updatePlayerPosInGrid(0, +1);
        }
        
        else if(!isCurrentRowEven() && isCurrentColumnEven())
        {
        //System.out.println("odd, even");
        updatePlayerPosInGrid(0, +1);
        }
        
        else if(isCurrentRowEven() && !isCurrentColumnEven())
        {
        //System.out.println("even, odd");
        updatePlayerPosInGrid(+1, +1);
        }
        
        else
        {
        //System.out.println("odd, odd");
        updatePlayerPosInGrid(+1, +1);
        }
        
    }
       
    
    
    private void updatePlayerPosInGrid(int x, int y)
    { 
        currentPosition[0] += x;
        currentPosition[1] += y;
    }
    
    private void updatePlayerPos(int x, int y)
    {
        xPos = x;
        yPos = y;
    }
    
    public int[] getCurrentPosInArray()
    {
        return currentPosition;
    }
    
    public int getCurrentXPosInGrid()
    {
        return currentPosition[0];
    }
    
    public int getCurrentYPosInGrid()
    {
        return currentPosition[1];
    }
    
    private void setXAndYPos(int x, int y)
    {
        xPos = x;
        yPos = y;
    }
    public int getXPos()
    {
        return xPos;
    }
    
    public int getYPos()
    {
        return yPos;
    }
    
    public void movePlayerNorthWest(SimpleGUI sGUI)
    {
        if(sGUI.getEngineUsed().requestPlayerMoveNorthWest(this, sGUI))
        {
            playerUpdatePosNorthWest();
        }
    }
    public void movePlayerNorth(SimpleGUI sGUI)
    {
   
    }
    
    public void movePlayerNorthEast(SimpleGUI sGUI)
    {
        if(sGUI.getEngineUsed().requestPlayerMoveNorthEast(this, sGUI))
        {
            playerUpdatePosNorthEast();
        }
    }
    public void movePlayerWest(SimpleGUI sGUI)
    {
        if(sGUI.getEngineUsed().requestPlayerMoveWest(this, sGUI))
        {
            playerUpdatePosWest();
        }
    }
    public void movePlayerEast(SimpleGUI sGUI)
    {
        if(sGUI.getEngineUsed().requestPlayerMoveEast(this, sGUI))
        {
            playerUpdatePosEast();
        }
    }
    
    public void movePlayerSouthWest(SimpleGUI sGUI)
    {
        if(sGUI.getEngineUsed().requestPlayerMoveSouthWest(this, sGUI))
        {
            playerUpdatePosSouthWest();
        }
    }
    
    public void movePlayerSouth(SimpleGUI sGUI)
    {
        
    }
    
    public void movePlayerSouthEast(SimpleGUI sGUI)
    {

        if(sGUI.getEngineUsed().requestPlayerMoveSouthEast(this, sGUI))
        {
            playerUpdatePosSouthEast();
        }
    }
    
        

}
